package com.huawei.appmarket.framework.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.RelativeLayout;

@SuppressLint({"NewApi"})
public class FixedMarginLayout extends RelativeLayout {
    private int ˊ = -1;
    private int ˎ = 0;
    private int ॱ = -1;

    public FixedMarginLayout(Context context) {
        super(context);
    }

    public FixedMarginLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public FixedMarginLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        int i3 = getContext().getResources().getConfiguration().orientation;
        if (this.ˊ == -1 || this.ॱ == -1 || this.ˎ != i3) {
            int measuredHeight = getMeasuredHeight();
            int childCount = getChildCount();
            if (measuredHeight > 0 && childCount >= 2) {
                MarginLayoutParams marginLayoutParams = (MarginLayoutParams) getLayoutParams();
                if (marginLayoutParams != null) {
                    ˎ(measuredHeight, childCount, i3, marginLayoutParams);
                }
            }
        }
    }

    private void ˎ(int i, int i2, int i3, MarginLayoutParams marginLayoutParams) {
        Object obj = null;
        if (marginLayoutParams.topMargin > 0 || marginLayoutParams.bottomMargin > 0) {
            int ॱ = ॱ(i2);
            if (ॱ <= 0 || ॱ >= i) {
                ॱ = 0;
            } else {
                ॱ = (i - ॱ) / 2;
            }
            if (ॱ > 0) {
                if (marginLayoutParams.topMargin >= 0) {
                    int i4 = marginLayoutParams.topMargin - ॱ;
                    if (i4 != this.ˊ) {
                        this.ˊ = i4;
                        this.ˎ = i3;
                        marginLayoutParams.topMargin = this.ˊ;
                        obj = 1;
                    }
                }
                if (marginLayoutParams.bottomMargin >= 0) {
                    ॱ = marginLayoutParams.bottomMargin - ॱ;
                    if (ॱ != this.ॱ) {
                        this.ॱ = ॱ;
                        this.ˎ = i3;
                        marginLayoutParams.bottomMargin = this.ॱ;
                        obj = 1;
                    }
                }
                if (obj != null) {
                    setLayoutParams(marginLayoutParams);
                }
            }
        }
    }

    private int ॱ(int i) {
        int i2 = -1;
        for (int i3 = 0; i3 < i; i3++) {
            View childAt = getChildAt(i3);
            if (childAt != null) {
                int measuredHeight = childAt.getMeasuredHeight();
                if (i2 == -1 || i2 > measuredHeight) {
                    i2 = measuredHeight;
                }
            }
        }
        return i2;
    }
}
